<template>
  <div class="app-container">
    <el-form ref="form" :model="form" :rules="rules" size="medium" label-width="100px">
      <el-form-item label="仓库编号" prop="warehouseNo">
        <el-input v-model="form.warehouseNo" placeholder="请输入仓库编号" />
      </el-form-item>
      <el-form-item label="仓库名称" prop="warehouseName">
        <el-input v-model="form.warehouseName" placeholder="请输入仓库名称" />
      </el-form-item>
      <el-form-item label="仓库简介" prop="warehouseDesc">
        <el-input v-model="form.warehouseDesc" type="textarea" placeholder="请输入内容" />
      </el-form-item>
      <el-form-item label="电话" prop="telephone">
        <el-input v-model="form.telephone" placeholder="请输入电话" />
      </el-form-item>
      <el-form-item label="邮编" prop="zip">
        <el-input v-model="form.zip" placeholder="请输入邮编" />
      </el-form-item>
      <el-form-item label="仓库地址" prop="addr">
        <el-input v-model="form.addr" placeholder="请输入仓库地址" />
      </el-form-item>
      <el-form-item size="large">
        <el-button type="primary" @click="submitForm">提交</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import user from "@/store/modules/user";
import {update3rdstockByAdd} from "@/api/supplier/3rdstock";
import { list3rdwarehouse, get3rdwarehouse, del3rdwarehouse, add3rdwarehouse, update3rdwarehouse } from "@/api/system/3rdwarehouse";


export default {
  components: {},
  props: [],
  data() {
    return {
      // formData: {
      //   warehouseId: user.status.id,
      //   warehouseNo: null,
      //   warehouseName:null,
      //   warehouseDesc: null,
      //   telephone: null,
      //   zip:null,
      //   addr: null,
      //   updateBy: user.state.id,
      // },
      // 表单参数
      form: {},

      rules: {
        warehouseName: [
          { required: true, message: "仓库名称不能为空", trigger: "blur" }
        ],
        warehouseNo: [
          { required: true, message: "仓库编号不能为空", trigger: "blur" }
        ],
        telephone: [
          { required: false, message: "电话不能为空", trigger: "blur" },
          { pattern: /^[\+]?[0-9]{0,3}[\-]?(13|14|15|16|17|18|19)[0-9]{9}|0\d{2,3}-\d{7,8}|^0\d{2,3}-\d{7,8}-\d{1,4}$/, message: "请输入正确的手机号码", trigger: "blur" }
        ],
        zip: [
          { required: false, message: "邮编不能为空", trigger: "blur" },
          { pattern: /^\d{6}$/, message: "请输入正确的邮编", trigger: "blur" }
        ],
        warehouseId: [
          { required: true, message: "仓库主键不能为空", trigger: "blur" }
        ],
        userId: [
          { required: true, message: "仓库用户主键不能为空", trigger: "blur" }
        ],
        updateBy: [
          { required: true, message: "最新更新者id不能为空", trigger: "blur" }
        ]
      },
    }
  },
  computed: {},
  watch: {},
  created() {
    get3rdwarehouse(user.state.id).then(response => {
      this.form = response.data;
      this.title = "修改第三方仓库信息";
    });
  },
  mounted() {},
  methods: {
    reset() {
      this.form = {
        warehouseId: user.status.id,
        warehouseNo: null,
        warehouseName: null,
        warehouseDesc: null,
        userId: null,
        telephone: null,
        zip: null,
        addr: null,
        createTime: null,
        updateTime: null,
        updateBy: user.state.id,
      };
      this.resetForm("form");
    },
    resetForm() {
      get3rdwarehouse(user.state.id).then(response => {
        this.form = response.data;
        this.title = "修改第三方仓库信息";
      });
    },
    submitForm() {
      if (this.form.updateBy == null) {
        this.$notify.error({
          title: '错误',
          message: '请先登录'
        });
        return;
      }
      if (this.form.warehouseId == null) {
        this.$notify.error({
          title: '错误',
          message: '请选择第三方仓库'
        });
        return;
      }

      this.$notify({
        title: '成功',
        message: '第三方仓库信息修改成功',
        type: 'success'
      });

      update3rdwarehouse(this.form).then(response => {
        console.log(response);
      });

    },

  }
}

</script>
<style>
</style>


<!--<script>-->
<!--import { list3rdwarehouse, get3rdwarehouse, del3rdwarehouse, add3rdwarehouse, update3rdwarehouse } from "@/api/system/3rdwarehouse";-->
<!--import user from "../../../store/modules/user";-->

<!--export default {-->
<!--  name: "3rdwarehouse",-->
<!--  data() {-->
<!--    return {-->
<!--      // 遮罩层-->
<!--      loading: true,-->
<!--      // 选中数组-->
<!--      ids: [],-->
<!--      // 非单个禁用-->
<!--      single: true,-->
<!--      // 非多个禁用-->
<!--      multiple: true,-->
<!--      // 显示搜索条件-->
<!--      showSearch: true,-->
<!--      // 总条数-->
<!--      total: 0,-->
<!--      // 第三方仓库信息表格数据-->
<!--      rdwarehouseList: [],-->
<!--      // 弹出层标题-->
<!--      title: "",-->
<!--      // 是否显示弹出层-->
<!--      open: false,-->
<!--      // 查询参数-->
<!--      queryParams: {-->
<!--        pageNum: 1,-->
<!--        pageSize: 10,-->
<!--        warehouseNo: null,-->
<!--        warehouseName: null,-->
<!--        warehouseDesc: null,-->
<!--        userId: null,-->
<!--        telephone: null,-->
<!--        zip: null,-->
<!--        addr: null,-->
<!--      },-->
<!--      // 表单参数-->
<!--      form: {},-->
<!--      // 表单校验-->
<!--      rules: {-->
<!--        warehouseId: [-->
<!--          { required: true, message: "仓库主键不能为空", trigger: "blur" }-->
<!--        ],-->
<!--        userId: [-->
<!--          { required: true, message: "仓库用户主键不能为空", trigger: "blur" }-->
<!--        ],-->
<!--        updateBy: [-->
<!--          { required: true, message: "最新更新者id不能为空", trigger: "blur" }-->
<!--        ]-->
<!--      }-->
<!--    };-->
<!--  },-->
<!--  created() {-->
<!--    this.reset();-->
<!--    get3rdwarehouse(user.state.id).then(response => {-->
<!--      this.form = response.data;-->
<!--      this.title = "修改第三方仓库信息";-->
<!--    });-->
<!--  },-->
<!--  methods: {-->
<!--    /** 查询第三方仓库信息列表 */-->
<!--    getList() {-->
<!--      this.loading = true;-->
<!--      list3rdwarehouse(this.queryParams).then(response => {-->
<!--        this.rdwarehouseList = response.rows;-->
<!--        this.total = response.total;-->
<!--        this.loading = false;-->
<!--      });-->
<!--    },-->
<!--    // 取消按钮-->
<!--    cancel() {-->
<!--      this.open = false;-->
<!--      this.reset();-->
<!--    },-->
<!--    // 表单重置-->
<!--    reset() {-->
<!--      this.form = {-->
<!--        warehouseId: null,-->
<!--        warehouseNo: null,-->
<!--        warehouseName: null,-->
<!--        warehouseDesc: null,-->
<!--        userId: null,-->
<!--        telephone: null,-->
<!--        zip: null,-->
<!--        addr: null,-->
<!--        createTime: null,-->
<!--        updateTime: null,-->
<!--        updateBy: null-->
<!--      };-->
<!--      this.resetForm("form");-->
<!--    },-->
<!--    /** 搜索按钮操作 */-->
<!--    handleQuery() {-->
<!--      this.queryParams.pageNum = 1;-->
<!--      this.getList();-->
<!--    },-->
<!--    /** 重置按钮操作 */-->
<!--    resetQuery() {-->
<!--      this.resetForm("queryForm");-->
<!--      this.handleQuery();-->
<!--    },-->
<!--    // 多选框选中数据-->
<!--    handleSelectionChange(selection) {-->
<!--      this.ids = selection.map(item => item.warehouseId)-->
<!--      this.single = selection.length!==1-->
<!--      this.multiple = !selection.length-->
<!--    },-->
<!--    /** 新增按钮操作 */-->
<!--    handleAdd() {-->
<!--      this.reset();-->
<!--      this.open = true;-->
<!--      this.title = "添加第三方仓库信息";-->
<!--    },-->
<!--    /** 修改按钮操作 */-->
<!--    handleUpdate(row) {-->
<!--      this.reset();-->
<!--      const warehouseId = row.warehouseId || this.ids-->
<!--      get3rdwarehouse(warehouseId).then(response => {-->
<!--        this.form = response.data;-->
<!--        this.open = true;-->
<!--        this.title = "修改第三方仓库信息";-->
<!--      });-->
<!--    },-->
<!--    /** 提交按钮 */-->
<!--    submitForm() {-->
<!--      this.form.updateBy=user.state.id;-->
<!--      this.$refs["form"].validate(valid => {-->
<!--        if (valid) {-->
<!--          if (this.form.warehouseId != null) {-->
<!--            update3rdwarehouse(this.form).then(response => {-->
<!--              this.$modal.msgSuccess("修改成功");-->
<!--              this.open = false;-->
<!--              this.getList();-->
<!--            });-->
<!--          } else {-->
<!--            this.form.warehouseId=this.form.userId;-->
<!--            add3rdwarehouse(this.form).then(response => {-->
<!--              this.$modal.msgSuccess("新增成功");-->
<!--              this.open = false;-->
<!--              this.getList();-->
<!--            });-->
<!--          }-->
<!--        }-->
<!--      });-->
<!--    },-->
<!--    /** 删除按钮操作 */-->
<!--    handleDelete(row) {-->
<!--      const warehouseIds = row.warehouseId || this.ids;-->
<!--      this.$modal.confirm('是否确认删除第三方仓库信息编号为"' + warehouseIds + '"的数据项？').then(function() {-->
<!--        return del3rdwarehouse(warehouseIds);-->
<!--      }).then(() => {-->
<!--        this.getList();-->
<!--        this.$modal.msgSuccess("删除成功");-->
<!--      }).catch(() => {});-->
<!--    },-->
<!--    /** 导出按钮操作 */-->
<!--    handleExport() {-->
<!--      this.download('system/3rdwarehouse/export', {-->
<!--        ...this.queryParams-->
<!--      }, `3rdwarehouse_${new Date().getTime()}.xlsx`)-->
<!--    }-->
<!--  }-->
<!--};-->
<!--</script>-->
